/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gft.bancosimulador.views;
import com.gft.bancosimulador.beans.*;
import com.gft.bancosimulador.business.ClienteBusiness;
import com.gft.bancosimulador.outros.Sucesso;
import com.gft.bancosimulador.enume.*;
import java.awt.Component;
import javax.swing.DefaultComboBoxModel;


import javax.swing.JOptionPane;
/**
 *
 * @author AEPI
 */
public abstract class ClienteView extends javax.swing.JInternalFrame {

    /**
     * Creates new form ClienteView
     */
    public ClienteView() {
        initComponents();
    }
    
    /*public ClienteView(int codigo){
        this();
        this.consultar(codigo);
}*/
    
    
    public abstract void salvar();
    //public abstract void consultar(int codigo);
    public abstract void bloquear();
    public abstract void reativar();
    public abstract void cancelar();
    protected abstract String getTitulo();
    protected abstract String getRotuloIdentificador();
    protected abstract String getFormatoMascaraIdentificador();
    
    public void limparFormulario(){
        this.cbx_UfCliente.contains(null);
        this.txt_CidadeCliente.setText("");
        this.txt_CodCliente.setText("");
        this.txt_CpfCnpjCliente.setText("");
        this.txt_EstadoCliente.setText("");
        this.txt_NomeCliente.setText("");
        this.cbx_UfCliente.setSelectedIndex(0);
    }
    
    public void preencherCliente(Cliente cliente){
        if(txt_CodCliente.getText()!=null && !txt_CodCliente.getText().isEmpty()){
            cliente.setCodigo(Integer.parseInt(txt_CodCliente.getText()));
            }
        cliente.setCidade(txt_CidadeCliente.getText());
        cliente.setNome(txt_NomeCliente.getText());
        UnidadeFederativa n;
        n = (UnidadeFederativa) cbx_UfCliente.getSelectedItem();
        cliente.setUnidadeFederativa(n);
       
    }
    
    public void exibirCliente(Cliente cliente){
        String codigo = Integer.toString(cliente.getCodigo());
        this.txt_CodCliente.setText(codigo);
        this.txt_CidadeCliente.setText(cliente.getCidade());
        this.txt_CpfCnpjCliente.setText(cliente.getDocumento());
        this.txt_NomeCliente.setText(cliente.getNome());
        this.cbx_UfCliente.setSelectedItem(cliente.getUnidadeFederativa());
        this.txt_EstadoCliente.setText(cliente.getSituacaoCliente().toString());
       
        
    }
    
    public void mostrarStatus(Sucesso i){
        Cliente cliente = (Cliente) i.getConteudo();
        this.exibirCliente(cliente);
        JOptionPane.showMessageDialog(this, i.getMsg());
    }
    
    public void consultar(int codigo) {
        
        Cliente cliente;
        cliente = ClienteBusiness.getInstance().consultarClientePorCodigo(codigo);
        this.exibirCliente(cliente);       
         
    }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_CodCliente = new javax.swing.JLabel();
        txt_CodCliente = new javax.swing.JTextField();
        lbl_EstadoCliente = new javax.swing.JLabel();
        btn_ConsultarCliente = new javax.swing.JButton();
        txt_EstadoCliente = new javax.swing.JTextField();
        lbl_NomeCliente = new javax.swing.JLabel();
        txt_NomeCliente = new javax.swing.JTextField();
        lbl_CidadeCliente = new javax.swing.JLabel();
        txt_CidadeCliente = new javax.swing.JTextField();
        lbl_UfCliente = new javax.swing.JLabel();
        cbx_UfCliente = new javax.swing.JComboBox();
        lbl_CpfCnpjCliente = new javax.swing.JLabel();
        txt_CpfCnpjCliente = new javax.swing.JTextField();
        btn_SalvarCliente = new javax.swing.JButton();
        btn_BloquearCliente = new javax.swing.JButton();
        btn_CancelarCliente = new javax.swing.JButton();
        btn_ReativarCliente = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setName(""); // NOI18N

        lbl_CodCliente.setText("Codigo Cliente:");

        txt_CodCliente.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

        lbl_EstadoCliente.setText("Estado Cliente:");

        btn_ConsultarCliente.setText("Consultar");
        btn_ConsultarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ConsultarClienteActionPerformed(evt);
            }
        });

        txt_EstadoCliente.setEnabled(false);
        txt_EstadoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_EstadoClienteActionPerformed(evt);
            }
        });

        lbl_NomeCliente.setText("Nome:");

        lbl_CidadeCliente.setText("Cidade:");

        txt_CidadeCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_CidadeClienteActionPerformed(evt);
            }
        });

        lbl_UfCliente.setText("Estado:");

        lbl_CpfCnpjCliente.setText("CPF / CNPJ:");

        btn_SalvarCliente.setText("Salvar");
        btn_SalvarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SalvarClienteActionPerformed(evt);
            }
        });

        btn_BloquearCliente.setText("Bloquear");
        btn_BloquearCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_BloquearClienteActionPerformed(evt);
            }
        });

        btn_CancelarCliente.setText("Cancelar");
        btn_CancelarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CancelarClienteActionPerformed(evt);
            }
        });

        btn_ReativarCliente.setText("Reativar");
        btn_ReativarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ReativarClienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbl_CpfCnpjCliente)
                            .addComponent(lbl_CidadeCliente)
                            .addComponent(lbl_NomeCliente)
                            .addComponent(lbl_CodCliente))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txt_CodCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btn_ConsultarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(lbl_EstadoCliente)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txt_EstadoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txt_NomeCliente)
                            .addComponent(txt_CidadeCliente)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txt_CpfCnpjCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lbl_UfCliente)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbx_UfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(btn_SalvarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btn_BloquearCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(btn_CancelarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(btn_ReativarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txt_CodCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbl_EstadoCliente)
                        .addComponent(btn_ConsultarCliente)
                        .addComponent(txt_EstadoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lbl_CodCliente))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_NomeCliente)
                    .addComponent(txt_NomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_CidadeCliente)
                    .addComponent(txt_CidadeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbx_UfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_UfCliente)
                    .addComponent(txt_CpfCnpjCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_CpfCnpjCliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_SalvarCliente)
                    .addComponent(btn_BloquearCliente)
                    .addComponent(btn_CancelarCliente)
                    .addComponent(btn_ReativarCliente))
                .addGap(24, 24, 24))
        );

        cbx_UfCliente.setModel(new DefaultComboBoxModel(UnidadeFederativa.values()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_CancelarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CancelarClienteActionPerformed
        // TODO add your handling code here:
        this.cancelar();
    }//GEN-LAST:event_btn_CancelarClienteActionPerformed

    private void txt_CidadeClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_CidadeClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_CidadeClienteActionPerformed

    private void btn_SalvarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SalvarClienteActionPerformed
        // TODO add your handling code here:  
        this.salvar();
    }//GEN-LAST:event_btn_SalvarClienteActionPerformed

    private void btn_ReativarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ReativarClienteActionPerformed
        // TODO add your handling code here:
        this.reativar();
    }//GEN-LAST:event_btn_ReativarClienteActionPerformed

    private void btn_BloquearClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_BloquearClienteActionPerformed
        // TODO add your handling code here:
        this.bloquear();
    }//GEN-LAST:event_btn_BloquearClienteActionPerformed

    private void btn_ConsultarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ConsultarClienteActionPerformed
        // TODO add your handling code here:
        int codigo = Integer.parseInt(txt_CodCliente.getText());
        this.consultar(codigo);
    }//GEN-LAST:event_btn_ConsultarClienteActionPerformed

    private void txt_EstadoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_EstadoClienteActionPerformed
        // TODO add your handling code here:       
    }//GEN-LAST:event_txt_EstadoClienteActionPerformed

    
   
     
       

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton btn_BloquearCliente;
    public javax.swing.JButton btn_CancelarCliente;
    private javax.swing.JButton btn_ConsultarCliente;
    public javax.swing.JButton btn_ReativarCliente;
    public javax.swing.JButton btn_SalvarCliente;
    public javax.swing.JComboBox cbx_UfCliente;
    private javax.swing.JLabel lbl_CidadeCliente;
    private javax.swing.JLabel lbl_CodCliente;
    public javax.swing.JLabel lbl_CpfCnpjCliente;
    private javax.swing.JLabel lbl_EstadoCliente;
    private javax.swing.JLabel lbl_NomeCliente;
    private javax.swing.JLabel lbl_UfCliente;
    public javax.swing.JTextField txt_CidadeCliente;
    private javax.swing.JTextField txt_CodCliente;
    public javax.swing.JTextField txt_CpfCnpjCliente;
    public javax.swing.JTextField txt_EstadoCliente;
    public javax.swing.JTextField txt_NomeCliente;
    // End of variables declaration//GEN-END:variables
}
